package com.mvp.shq.washer.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.rxbus.BusData;
import com.mvp.shq.washer.rxbus.RxBus;
import com.mvp.shq.washer.utils.EventCode;
import com.orhanobut.logger.Logger;
import com.zhy.autolayout.AutoLinearLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/21.
 */

public class OrderAdapter extends RecyclerView.Adapter<OrderAdapter.ViewHolder> {

    private List<String> data;

    public OrderAdapter(List<String> list) {
        data = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_order, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (position == 0){
            holder.division.setVisibility(View.VISIBLE);
            holder.allOrderView.setVisibility(View.GONE);
            return;
        }
        holder.division.setVisibility(View.GONE);
        holder.allOrderView.setVisibility(View.VISIBLE);
        holder.allOrderView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Logger.d("点击item："+position);
                BusData data = new BusData();
                data.setPosition(position);
                RxBus.get().send(EventCode.ORDER_ITEM_CLICK,data);
            }
        });
        int bgType = position%4;
        switch (bgType){
            case 0:
                holder.allOrderView.setBackgroundResource(R.drawable.order_item_1);
                break;
            case 1:
                holder.allOrderView.setBackgroundResource(R.drawable.order_item_2);
                break;
            case 2:
                holder.allOrderView.setBackgroundResource(R.drawable.order_item_3);
                break;
            case 3:
                holder.allOrderView.setBackgroundResource(R.drawable.order_item_4);
                break;
        }
    }

    @Override
    public int getItemCount() {
        return data.size() + 1;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_order_no)
        TextView tvOrderNo;
        @BindView(R.id.tv_order_state)
        TextView tvOrderState;
        @BindView(R.id.tv_order_time)
        TextView tvOrderTime;
        @BindView(R.id.tv_order_location)
        TextView tvOrderLocation;
        @BindView(R.id.tv_order_number)
        TextView tvOrderNumber;
        @BindView(R.id.tv_order_model)
        TextView tvOrderModel;
        @BindView(R.id.tv_order_money)
        TextView tvOrderMoney;
        @BindView(R.id.all_order_view)
        AutoLinearLayout allOrderView;
        @BindView(R.id.division)
        View division;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
